﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using SEiBuyAgency.User;
using SEiBuyAgency.Factory;

namespace SEiBuyAgency
{
    public partial class RegForm : Form,IUserActionObserver
    {
        CUser user;
        private CUser creatUser(ICreator x )
        {
           return  x.FactoryMethod(this);
        }


        public RegForm()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(this.textBox2.Text==this.textBox3.Text&&this.textBox1.Text!=""&&this.textBox2.Text!="")
            {
               //reg
                user = this.creatUser(new UserL1Creator());
                user.Regist(this.textBox1.Text, textBox2.Text, textBox4.Text);
            }
            else
            {
                this.label6.Text = "输入有误！";
            }
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            this.label6.Text = "";
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            this.label6.Text = "";
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.label6.Text = "";
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            this.label6.Text = "";
        }



        #region IUserActionObserver 成员

        public void Completely(TAction action, bool suc)
        {
            if (suc&&action == TAction.ERegist)
            {
                MessageBox.Show("注册成功！");
                this.Close();
            }
            else
                MessageBox.Show("注册失败！注册账号已存在！");   
        }
        #endregion
    }
}
